package net.heri.xmppchat.activities;

import net.heri.xmppchat.R;
import net.heri.xmppchat.activities.chatroom.ChatRoomActivity;
import net.heri.xmppchat.activities.contactlist.ContactListActivity;
import net.heri.xmppchat.controllers.RecentChatController;
import net.heri.xmppchat.controllers.RecentChatControllerEvents;
import roboguice.activity.RoboActivity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.google.inject.Inject;

@ContentView(R.layout.recent_chat_activity)
public class RecentChatActivity extends RoboActivity implements OnClickListener {

	private final String TAG = RecentChatActivity.class.getSimpleName();
	
	@InjectView(R.id.tv_label) TextView label;
	@InjectView(R.id.bt_settings) Button settingButton;
	@InjectView(R.id.bt_update) Button updateButton;	
	@InjectView(R.id.bt_start_chat) Button startChatButton;
	@InjectView(R.id.bt_contact_list) Button contactListButton;
	
	@Inject private RecentChatController mController;
	
	private Handler mHandler = new Handler(){
		public void handleMessage(Message msg) {
			label.setText((String)msg.obj);
		};
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		
		mController.setHandler(mHandler);
		
		settingButton.setOnClickListener(this);		
		updateButton.setOnClickListener(this);	
		startChatButton.setOnClickListener(this);
		contactListButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.bt_settings: {
				Log.i(TAG, "start settingActivity");
				
				Intent intent = new Intent(RecentChatActivity.this, ChatSettingsActivity.class);
				startActivity(intent);
				break;
			}
			case R.id.bt_update: {
				Log.i(TAG, "start settingActivity");
				
				eventManager.fire(new RecentChatControllerEvents.OnLabelChanged());
				break;
			}
			case R.id.bt_start_chat : {
				Intent intent = new Intent(this, ChatRoomActivity.class);
				startActivity(intent);
				break;
			}
			case R.id.bt_contact_list : {
				Intent intent = new Intent(this, ContactListActivity.class);
				startActivity(intent);
				break;
			}
		}
	}
	
}
